CREATE PROCEDURE coreWFTaskingSave
(
	@id						int output,
	@FK_ProcessID			int,
	@TaskCaption			nvarchar(500),
	@CSV_OperatorID			nvarchar(500),
	@CSV_GroupID			nvarchar(500),
	@GetUserMethod			nvarchar(500),
	@SystemTask				bit,
	@SystemExitAt			int,
	@SystemExitAtUnit		int,
	@ActivateTaskAt			int,
	@ActivateTaskAtUnit		int,
	@DeadlineTaskAt			int,
	@DeadlineTaskAtUnit		int
)
AS
BEGIN
	IF @id = -1
	BEGIN
		SET NOCOUNT ON;
		
		INSERT INTO WFTasking 
			( FK_ProcessID, TaskCaption, CSV_OperatorID, CSV_GroupID, GetUserMethod,
			  SystemTask, SystemExitAt, SystemExitAtUnit, ActivateTaskAt, ActivateTaskAtUnit,
			  DeadlineTaskAt, DeadlineTaskAtUnit )
		VALUES 
			( @FK_ProcessID, @TaskCaption, @CSV_OperatorID, @CSV_GroupID, @GetUserMethod,
			  @SystemTask, @SystemExitAt, @SystemExitAtUnit, @ActivateTaskAt, @ActivateTaskAtUnit,
			  @DeadlineTaskAt, @DeadlineTaskAtUnit )

		SET NOCOUNT OFF;
		SELECT @id = @@IDENTITY;

	END
	ELSE
	BEGIN

		UPDATE WFTasking SET
			TaskCaption			= @TaskCaption,
			CSV_OperatorID		= @CSV_OperatorID,
			CSV_GroupID			= @CSV_GroupID,
			GetUserMethod		= @GetUserMethod,
			SystemTask			= @SystemTask,
			SystemExitAt		= @SystemExitAt,
			SystemExitAtUnit	= @SystemExitAtUnit,
			ActivateTaskAt		= @ActivateTaskAt,
			ActivateTaskAtUnit	= @ActivateTaskAtUnit,
			DeadlineTaskAt		= @DeadlineTaskAt,
			DeadlineTaskAtUnit	= @DeadlineTaskAtUnit
		WHERE PK_ID=@id;
		
	END
	
END
